﻿using Newtonsoft.Json.Linq;

namespace ACSynologyHelper
{
    /// <summary>
    /// SynologyResult类扩展方法类
    /// </summary>
    public static class SynologyResultException
    {
        /// <summary>
        /// 获取登录时的SID
        /// </summary>
        public static string GetLoginSID(this SynologyResult synologyResult)
        {
            if (synologyResult.data == null) { return ""; }
            if (synologyResult.data.TryGetValue("sid", out JToken jToken))
            {
                return jToken.Value<string>();
            }
            else
            {
                return "";
            }
        }

        /// <summary>
        /// 获取错误代码
        /// </summary>
        public static string GetErrorCode(this SynologyResult synologyResult)
        {
            if (synologyResult.error == null) { return ""; }
            if (synologyResult.data.TryGetValue("code", out JToken jToken))
            {
                return jToken.Value<string>();
            }
            else
            {
                return "";
            }
        }
    }
}
